import 'package:in_app_purchase/in_app_purchase.dart';

class ChanPinGuanli {
  Set<String> kIds = <String>{
    "net.super.week.pro",
    "net.super.month.pro",
    "net.super.year.pro"
  };

  factory ChanPinGuanli() => _getInstance();

  static ChanPinGuanli get instance => _getInstance();
  static ChanPinGuanli? _instance;
  List<ProductDetails> chanpinLiebiao = [];

  ChanPinGuanli._internal();

  static ChanPinGuanli _getInstance() {
    _instance ??= ChanPinGuanli._internal();
    return _instance!;
  }

  huoquCHanpin() async {
    final ProductDetailsResponse response =
        await InAppPurchase.instance.queryProductDetails(kIds);
    if (response.notFoundIDs.isNotEmpty) {
      // Handle the error.
    }
    chanpinLiebiao = response.productDetails;
  }

  ProductDetails huoquzhou() {
    late ProductDetails mubioaoxiangqing;
    for (ProductDetails productDetails in chanpinLiebiao) {
      if (productDetails.id == kIds.elementAt(0)) {
        mubioaoxiangqing = productDetails;
        break;
      }
    }
    return mubioaoxiangqing;
  }

  ProductDetails huoquYue() {
    late ProductDetails mubioaoxiangqing;
    for (ProductDetails productDetails in chanpinLiebiao) {
      if (productDetails.id == kIds.elementAt(1)) {
        mubioaoxiangqing = productDetails;
        break;
      }
    }
    return mubioaoxiangqing;
  }

  ProductDetails huoquNian() {
    late ProductDetails mubioaoxiangqing;
    for (ProductDetails productDetails in chanpinLiebiao) {
      if (productDetails.id == kIds.elementAt(2)) {
        mubioaoxiangqing = productDetails;
        break;
      }
    }
    return mubioaoxiangqing;
  }
}
